<?php
if (isset($_SESSION['admin-login'])) {
	if (isset($_POST['post'])) {
		$judul = amankan($_POST['judul']);
		$textform = amankan($_POST['textform']);
		if (strlen($judul) == 0 || strlen($textform) == 0) {
			$_SESSION['status-blog-new'] = "Semua input harus diisi";
			header("Location: ".site()."/".$param[0]."/blog-new");
		} else {
			$tgl = date("Y-m-d H:i:s");
			$id = db_insert("INSERT INTO blog (judul,tgl,textform) VALUES ('$judul','$tgl','$textform')");
			$slug = slugging($_POST['judul'],"blog",$id);
			db_query("UPDATE blog SET slug = '$slug' WHERE id = $id");
			$_SESSION['status-blog'] = "Blog sudah dipost";
			header("Location: ".site()."/".$param[0]."/blog");
		}
	}
} else {
	$_SESSION['status-login'] = "Log in terlebih dahulu untuk melanjutkan";
	header("Location: ".site()."/".$param[0]."/login");
}
?>